package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.EstateAdviserService;
import com.yixun.qfbao.apidto.*;
import com.yixun.qfbao.apidto.base.CommonResDTO;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.EditEstateAdviserReqVo;
import com.yixun.qfbao.vo.GetPremisesDetailReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service("editEstateAdviserHander")
public class EditEstateAdviserHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(EditEstateAdviserHander.class);

    @Autowired
    EstateAdviserService estateAdviserService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        EditEstateAdviserReqVo req = (EditEstateAdviserReqVo)reqDto;
        EditEstateAdviserReqDto reqDto1 = req.getParams();
        BaseResponseDTO<CommonResDTO> res = new BaseResponseDTO<>();
        CommonResDTO resDto = new CommonResDTO();
        try {
            if(Objects.nonNull(reqDto1.getEstateAdviser().getId())){
                estateAdviserService.deleteEstateAdviserById(reqDto1.getEstateAdviser().getId());
            }
            resDto.setResult(ResultEnum.SUCCESS.getNo());
            res.setResData(resDto);
            res.setResult(ResultEnum.SUCCESS.getNo());
        }catch (Exception e){
            logger.error("delete estate adviser, id: {}, error: {}", reqDto1.getEstateAdviser().getId(), e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("置业顾问删除失败!");
        }
        return res;
    }
}
